package cac.fenjian.resource.PointPackageSort.rest;

import cac.fenjian.resource.PointPackageSort.dao.PackageAoQueryDao;
import cac.fenjian.resource.PointPackageSort.service.PackageAoQueryService;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("packageAoQueryRest")
public class PackageAoQueryRest {
    @Autowired
    private PackageAoQueryDao packageAoQueryDao;
    @Autowired
    private PackageAoQueryService packageAoQueryService;


    @PostMapping("seachAo")
    public PageInfo seachAo(@RequestBody HashMap map){
        HashMap page = (HashMap) map.get("page");
        HashMap queryParam = (HashMap) map.get("queryParam");
        int currentPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        PageHelper.startPage(currentPage,pageSize);
        List<HashMap> list = packageAoQueryDao.seachAo(queryParam);
        return new PageInfo(list);
    }



    @PostMapping("searchAoMatchById")
    public List<HashMap> searchAoMatchById(@RequestBody HashMap map){
        return packageAoQueryDao.queryMatchInfo(map);
    }
    @PostMapping("queryAo")
    public PageInfo queryAo(@RequestBody HashMap map){
        HashMap page = (HashMap) map.get("page");
        HashMap queryParam = (HashMap) map.get("queryParam");
        int currentPage = Integer.parseInt(page.get("currentPage").toString());
        int pageSize = Integer.parseInt(page.get("pageSize").toString());
        PageHelper.startPage(currentPage,pageSize);
        List<HashMap> list = packageAoQueryDao.queryAo(queryParam);
        return new PageInfo(list);
    }
    @PostMapping("searchAoBillById")
    public List<HashMap> searchAoBillById(@RequestBody HashMap map){
        return packageAoQueryDao.queryAoBillInfo(map);
    }

    /***
     * map:{msAoMatchBillId ,itemCode}
     * */
    @PostMapping("searchHandleMatchInfo")
    public HashMap searchHandleMatchInfo(@RequestBody HashMap map){
        HashMap billInfo = packageAoQueryDao.queryAoBillInfoByBillInfoId(map);
        map.put("aoCode",billInfo.get("aoCode"));
        List<HashMap> workbins = packageAoQueryDao.queryWorkbinMaterial(map);
        List<HashMap> matchInfos = packageAoQueryDao.queryMatchInfoByBIllId(map);
        HashMap result = new HashMap();
        result.put("billInfo",billInfo);
        result.put("matchInfos",matchInfos);
        result.put("workbins",workbins);
        return result;
    }
    @PostMapping("handleMatch")
    public ResponseMsg handleMatch(@RequestBody HashMap map){
        return packageAoQueryService.handleMatch(map);
    }

    @PostMapping("remmoveMatchInfo")
    public ResponseMsg remmoveMatchInfo(@RequestBody HashMap map){
        return packageAoQueryService.remmoveMatchInfo(map);
    }
}
